package com.runda.system.service.impl;

import java.util.Date;
import java.util.List;

import com.bbjob.model.SysDictionary;
import com.bbjob.util.service.impl.BaseService;
import com.github.pagehelper.util.StringUtil;
import com.runda.system.service.DicService;

import org.springframework.stereotype.Service;

import tk.mybatis.mapper.entity.Example;

@Service
public class DicServiceImpl extends BaseService<SysDictionary> implements DicService {

	

	@Override
	public int saveDic(SysDictionary dic) {
		dic.setCreateTime(new Date());
		return this.mapper.insertSelective(dic);
	}

	@Override
	public int editDic(SysDictionary dic) {
		return this.mapper.updateByPrimaryKeySelective(dic);
	}

	@Override
	public int deleteDic(Integer id) {
		return this.mapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<SysDictionary> selectAll(SysDictionary dic) {
		Example example = new Example(SysDictionary.class);
		Example.Criteria criteria = example.createCriteria();
		if (StringUtil.isNotEmpty(dic.getDicValue())) {
			criteria.andLike("dicValue", "%" + dic.getDicValue() + "%");
		}
		if (StringUtil.isNotEmpty(dic.getDicKey())) {
			criteria.andLike("dicKey", "%" + dic.getDicKey() + "%");
		}
		example.setOrderByClause("dic_key asc, no  asc");
		List<SysDictionary> resultList = this.mapper.selectByExample(example);
		return resultList;
	}

	@Override
	public List<SysDictionary> getDifficulty() {
		Example example = new Example(SysDictionary.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("dicKey", "difficulty_key");
		example.setOrderByClause("dic_key asc, no  asc");
		List<SysDictionary> resultList = this.mapper.selectByExample(example);
		return resultList;
	}

	
	public List<SysDictionary> selectByPkey(String pkey) {
		Example example =new Example(SysDictionary.class);
		example.createCriteria().andEqualTo("pKey", pkey);
		example.orderBy("no");
		return this.mapper.selectByExample(example);
	}

}